//
//  BEOrderDetailHeader
//  BEGlobalOiler
//
//  Created by KKING on 16/9/9.
//  Copyright © 2016年 Bullseye Energy pte ltd. All rights reserved.
//

import UIKit

class BEOrderDetailHeadCell: UITableViewCell {
    
    @IBOutlet weak var priceTotalLabel: UILabel!
    
    var detailModel: BEOrderDetailModel = BEOrderDetailModel(dict:["":"" as AnyObject]){
        didSet{
            orderStatulbl.text = detailModel.orderStatusName
            priceTotalLabel.text = "\(detailModel.estimateAmount)" + "$"
            rigNamelbl.text = detailModel.rigName
            rigLocationlbl.text = detailModel.rigLocation
            newDetailView.detailModel = detailModel

            exStartDatelbl.text = detailModel.expectStartTime
            exEndDatelbl.text = detailModel.expectEndTime
            acStartDatelbl.text = detailModel.requireStartTime
            acEndDatelbl.text = detailModel.requireEndTime
            
            guard let requestDate = detailModel.expectStartTime else{
                return
            }
            requestDatelbl.text = "Request Date : " + requestDate
        }
    }
    
    @IBOutlet weak var orderStatulbl: UILabel!
    @IBOutlet weak var rigNamelbl: UILabel!
    @IBOutlet weak var rigLocationlbl: UILabel!
    @IBOutlet weak var requestDatelbl: UILabel!
    
    //时间label
    @IBOutlet weak var exStartDatelbl: UILabel!
    @IBOutlet weak var exEndDatelbl: UILabel!
    @IBOutlet weak var acStartDatelbl: UILabel!
    @IBOutlet weak var acEndDatelbl: UILabel!
    
    
    
    
    @IBOutlet weak var detailView: UIView!
    
    var isopen:Bool = true
    
    var openHeaderBlock: ((_ openButton :UIButton,_ open: Bool) -> (Bool))?
    
    private lazy var newDetailView: BEDetailView = (BEDetailView.detailView() as? BEDetailView)!
    
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
//        let labelTap = UITapGestureRecognizer(target: self, action: #selector(labelTouchUp(recognizer:)))
//        priceTotalLabel.addGestureRecognizer(labelTap)
    }
    
    
    
    
    @objc private func labelTouchUp(recognizer: UITapGestureRecognizer){
        
        NotificationCenter.default.post(name: NSNotification.Name(rawValue: PushPriceTotalController), object: nil)
    }
    
    
    
    @IBAction func openButtonDidClick(sender: UIButton) {
        isopen = openHeaderBlock!(sender,isopen)
        if isopen{
            newDetailView.removeFromSuperview()
            detailView.isHidden = true
        }else{
            detailView.isHidden = false
            detailView.addSubview(newDetailView)
        }
    }

}
